package org.yxing.palpalgps.adapter;

import java.util.ArrayList;

import org.yxing.palpalgps.R;
import org.yxing.palpalgps.models.School;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SchoolAdapter extends BaseAdapter {
    private ArrayList<School> data;
    
    private Context mContext;
    
    public SchoolAdapter(Context context) {
        mContext = context;
        data = new ArrayList<School>();
    }

    public int getCount() {
        return data.size();
    }

    public School getItem(int position) {
        return data.get(position);
    }

    public long getItemId(int position) {
        return getItem(position).getSid();
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        School school = getItem(position);
        
        convertView = LayoutInflater.from(mContext).inflate(R.layout.group_item, null);
        ImageView iconImageView = (ImageView) convertView.findViewById(R.id.iconImageView);
        TextView nameTextView = (TextView) convertView.findViewById(R.id.nameTextView);
        nameTextView.setText(school.getName());
        return convertView;
    }

    public void addItem(School school) {
        data.add(school);
        notifyDataSetChanged();
    }
    
    public void clear() {
        data.clear();
    }
}
